<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>基于javascript的视图驱动</title>
</head>

<body>
    <h1>1</h1>
    <button>按我加1</button>
    <button id="button11">按我减1</button>
    <script>
        var elh1 = document.getElementsByTagName("h1")[0];
        // console.log("elh1:" + elh1)
        var button1=document.getElementsByTagName("button")[0];
        var button2=document.getElementById("button11");
        var num=0;
        button2.onclick=function(){
            num--;
            elh1.innerHTML=num;
        }
        button1.onclick=function(){
            num++;
            elh1.innerHTML=num;
        }


    </script>
</body>

</html>